package dem2;


import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-03-08
 * Time: 10:52
 */
class Person {
    public int age;
    public String name;

    public Person(String name,int age) {
        this.age = age;
        this.name = name;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name);
    }
}

public class Test {

    public static void main(String[] args) {
        Person person1 = new Person("xiaohei",12);
        Person person2 = new Person("xiaohei",12);
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }

    /*public static void main1(String[] args) {
        Person person1 = new Person("xiaohei",12);
        Person person2 = new Person("xiaohei",12);
        System.out.println(person1.equals(person2));
        System.out.println(person1==person2);
    }*/
}
